
angular.module('myApp').controller('q-gc',['$css','$http','$scope',function($css,$http,$scope){
	$css.add('./clothes/css/guangchang.css');
	
//	解析数据
	$http.get('./data/gc.json').success(function(data){
		console.log(data)
		$scope.arr=data.data;

	})
		
	$(document).ready(function(){	
		var arr=['./data/gc1.json','./data/gc3.json','./data/gc2.json'];
		var index=0;
		$(window).scroll(function(){
				var $maxHeight = $(document).height()-$(window).height();				
				var $sum = $(document).scrollTop()
				if(index>2){
					return
				}
				if($sum>=$maxHeight){
					$http.get(arr[index]).success(function(datas){
						
				
                    puBu(datas)
                    
                  
					})
					index++;
				}				
			})
					
			function randomFun(min,max){
			return  parseInt(Math.random()*(max - min)+min);
		}
				var $uls=$('.ul');
			
			
		function puBu(datas){
			var data=datas.data;
				for(var obj of data){				
					var $li =$('<li></li>');
					$li.width('100%');
					var h = randomFun(300,350);
					
					$li.height(h);
					
					minHeight=$uls[0];
					
					for(var j=0; j<$uls.length; j++){
						if(minHeight.offsetHeight>=$uls[j].offsetHeight){
							minHeight=$uls[j];
						}
					}					
					$(minHeight).append($li);
					var $img=$('<img>');
					var imgSrc=obj.data.imageUrl;
					var topic=obj.data.topic;
					var nickName=obj.data.nickName;
					var address=obj.data.address;
					$img.attr('src',imgSrc);
					
					$img.css({
						'width':'100%',
						'height':'100%'
					});
					$li.append($img);

				}			
		}
		
		
		
		
		
		
		setTimeout(banner,100) 
		
      function banner(){
          var $ban=$('#q-ban');
          var $trun = $('#q-turn');
          var $imgs = $('.imgs');
      	  var $dians = $('#q-turn>.q-dot>span'); 
          var w = parseInt($trun.css('width'));
//        console.log($ban)
//        $ban.width(w*$imgs.length);

          var index = 0;

                 for(var j=0 ; j<$dians.length; j++){
      				$dians[j].style.background='#c8cece';	
      			}
     $dians[0].style.background='green';
          function nextFn(){
      			index++;
            if(index > $imgs.length-1){
              index=0;
            }
            for(var j=0 ; j<$dians.length; j++){
      				$dians[j].style.background='#c8cece';	
      			}
      			$dians[index].style.background='green';
          var left1 = index*w *- 1;
          $ban.css('left',left1)
           }
          function clearTimer(){
            clearInterval(timer);
            timer = setInterval(nextFn , 2000);
          }
          var timer = setInterval(nextFn , 2000);
          var ban=document.querySelector('#q-ban')
          	ban.addEventListener('touchstart', function (e) {
                var touch = e.targetTouches[0];
                startX = touch.pageX;
            });
            ban.addEventListener('touchmove', function (e) {
                var touch = e.targetTouches[0];
                endX = touch.pageX;
                clearInterval(timer);
            })
            ban.addEventListener('touchend', function (e) {
                if (endX - startX > 100) {
                	index--;           			
						if(index<0){
							index = $imgs.length-1;
						}							
						for(var j=0 ; j<$dians.length; j++){
      						$dians[j].style.background='#c8cece';      				
      					}
      					$dians[index].style.background='green';						
						var left = index*w*-1;
						$ban.css('left',left);
						clearTimer();                                 
                } else if (endX - startX < -100) {
                		nextFn();
						clearTimer();                       
                }
                   clearTimer(); 
            })
        }	
})

}])
  
angular.module('myApp').controller('q-ren',['$css','$scope','$http',function($css,$scope,$http){

	
	
	
	$(document).ready(function(){	
		var arr=['./data/gc3.json','./data/gc2.json'];
		var index=0;
		$http.get('./data/gc1.json').success(function(datas){
		console.log(datas)
		puBu(datas)

	})
		
		
		$(window).scroll(function(){
				var $maxHeight = $(document).height()-$(window).height();				
				var $sum = $(document).scrollTop()
				if(index>1){
					return
				}
				if($sum>=$maxHeight){
					$http.get(arr[index]).success(function(datas){
                    puBu(datas)
                    
                  
					})
					index++;
				}				
			})
					
			function randomFun(min,max){
			return  parseInt(Math.random()*(max - min)+min);
		}
				var $uls=$('.ul');
				
				$uls.css({
					'float': 'left',
					'width': '48%',
					'margin-left': '0.1rem'
				})
			
			
		function puBu(datas){
			var data=datas.data;
				for(var obj of data){				
					var $li =$('<li></li>');
					$li.width('100%');
					var h = randomFun(300,350);
					console.log('ha')
					
					$li.height(h);
					$li.css('margin-top','0.1rem');
					
					minHeight=$uls[0];
					
					for(var j=0; j<$uls.length; j++){
						if(minHeight.offsetHeight>=$uls[j].offsetHeight){
							minHeight=$uls[j];
						}
					}					
					$(minHeight).append($li);
					var $img=$('<img>');
					var imgSrc=obj.data.imageUrl;
					var topic=obj.data.topic;
					var nickName=obj.data.nickName;
					var address=obj.data.address;
					$img.attr('src',imgSrc);
					
					$img.css({
						'width':'100%',
						'height':'100%'
					});
					$li.append($img);

				}			
		}
		
		
		
		
		
	
})
	
	
	
}])


angular.module('myApp').controller('q-reng',['$css','$scope','$http',function($css,$scope,$http){

	
	
	
	$(document).ready(function(){	
		var arr=['./data/gc2.json','./data/gc1.json'];
		var index=0;
		$http.get('./data/gc3.json').success(function(datas){
		console.log(datas)
		puBu(datas)

	})
		
		
		$(window).scroll(function(){
				var $maxHeight = $(document).height()-$(window).height();				
				var $sum = $(document).scrollTop()
				if(index>1){
					return
				}
				if($sum>=$maxHeight){
					$http.get(arr[index]).success(function(datas){
                    puBu(datas)
                    
                  
					})
					index++;
				}				
			})
					
			function randomFun(min,max){
			return  parseInt(Math.random()*(max - min)+min);
		}
				var $uls=$('.ul');
				
				$uls.css({
					'float': 'left',
					'width': '48%',
					'margin-left': '0.1rem'
				})
			
			
		function puBu(datas){
			var data=datas.data;
				for(var obj of data){				
					var $li =$('<li></li>');
					$li.width('100%');
					var h = randomFun(300,350);
					console.log('ha')
					
					$li.height(h);
					$li.css('margin-top','0.1rem');
					
					minHeight=$uls[0];
					
					for(var j=0; j<$uls.length; j++){
						if(minHeight.offsetHeight>=$uls[j].offsetHeight){
							minHeight=$uls[j];
						}
					}					
					$(minHeight).append($li);
					var $img=$('<img>');
					var imgSrc=obj.data.imageUrl;
					var topic=obj.data.topic;
					var nickName=obj.data.nickName;
					var address=obj.data.address;
					$img.attr('src',imgSrc);
					
					$img.css({
						'width':'100%',
						'height':'100%'
					});
					$li.append($img);

				}			
		}
		
		
		
		
		
	
})
	
	
	
}])

  

